/**
 * 
 */
package cz.cvut.fit.crhonjar.mi.run.hawera.tree.expression;

import cz.cvut.fit.crhonjar.mi.run.hawera.exception.HaweraException;
import cz.cvut.fit.crhonjar.mi.run.hawera.tree.TreeVisitor;

/**
 * litreral internal representation
 * 
 * @author Jarec
 * 
 */
public class LiteralTree extends ExpressionTree {

	private ExpressionType type;
	private Object value;

	/**
	 * constructs literal tree
	 * 
	 * @param type
	 * @param value
	 */
	public LiteralTree(ExpressionType type, Object value) {
		super();
		log.debug("> LiteralTree - operator: {}, value: {}", type, value);
		if (type == null) {
			final String message = "Cannot construct literalTree using null type!";
			log.error(message);
			throw new NullPointerException(message);
		}
		if (value == null) {
			final String message = "Cannot construct literalTree using null value!";
			log.error(message);
			throw new NullPointerException(message);
		}
		this.type = type;
		this.value = value;
	}

	/**
	 * @return the value
	 */
	public Object getValue() {
		return value;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * cz.cvut.fit.crhonjar.mi.run.hawera.tree.TreeVisitorAcceptor#accept(cz
	 * .cvut.fit.crhonjar.mi.run.hawera.tree.TreeVisitor)
	 */
	@Override
	public void accept(TreeVisitor visitor) {
		visitor.visitLiteral(this);

	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see cz.cvut.fit.crhonjar.mi.run.hawera.tree.expression.ExpressionTree#
	 * evaluableAtCompileTime()
	 */
	@Override
	public boolean evaluableAtCompileTime() throws HaweraException {
		log.debug(">< evaluableAtCompileTime result: true");
		return true;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * cz.cvut.fit.crhonjar.mi.run.hawera.tree.expression.ExpressionTree#getType
	 * ()
	 */
	@Override
	public ExpressionType getType() throws HaweraException {
		if (log.isDebugEnabled())
			log.debug(">< getType result: {}", this.type);
		return this.type;
	}

}
